package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.JijinFreeNumberMapper;
import work.xiaohong.gupiao.pojo.JijinFreeNumber;
import work.xiaohong.gupiao.service.JijinFreeNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JijinFreeNumberServiceImpl implements JijinFreeNumberService {

    @Autowired
    private JijinFreeNumberMapper jijinFreeNumberMapper;


    /**
     * 条件+分页查询JijinFreeNumber
     * @param jijinFreeNumber 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<JijinFreeNumber> findPage(JijinFreeNumber jijinFreeNumber, int page, int size){
        // 构建查询条件
        QueryWrapper<JijinFreeNumber> queryWrapper = new QueryWrapper<JijinFreeNumber>(jijinFreeNumber);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return jijinFreeNumberMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询JijinFreeNumber
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<JijinFreeNumber> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return jijinFreeNumberMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法JijinFreeNumber
     * @param jijinFreeNumber
     * @return
     */
    @Override
    public List<JijinFreeNumber> findList(JijinFreeNumber jijinFreeNumber){
        // 构建查询条件
        QueryWrapper<JijinFreeNumber> queryWrapper = new QueryWrapper<JijinFreeNumber>(jijinFreeNumber);
        // 查询数据
        return jijinFreeNumberMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除JijinFreeNumber
     * @param id
     */
    @Override
    public void delete(Integer id){
        jijinFreeNumberMapper.deleteById(id);
    }

    /**
     * 根据ID修改JijinFreeNumber
     * @param jijinFreeNumber
     */
    @Override
    public void update(JijinFreeNumber jijinFreeNumber){
        // 初始化一些不可修改数据
        jijinFreeNumber.setGmtModified(null);
        jijinFreeNumber.setGmtCreate(null);
        jijinFreeNumber.setVersion(null);
        jijinFreeNumber.setDeleted(null);
        jijinFreeNumberMapper.updateById(jijinFreeNumber);
    }

    /**
     * 增加JijinFreeNumber
     * @param jijinFreeNumber
     */
    @Override
    public void add(JijinFreeNumber jijinFreeNumber){
        jijinFreeNumberMapper.insert(jijinFreeNumber);
    }

    /**
     * 根据ID查询JijinFreeNumber
     * @param id
     * @return
     */
    @Override
    public JijinFreeNumber findById(Integer id){
        return  jijinFreeNumberMapper.selectById(id);
    }

    /**
     * 查询全部JijinFreeNumber数据
     * @return
     */
    @Override
    public List<JijinFreeNumber> findAll() {
        return jijinFreeNumberMapper.selectList(null);
    }
}
